package com.wswy.wyjk.db

import com.wswy.wyjk.core.App
import com.wswy.wyjk.model.*
import com.wswy.wyjk.model.dto.ExamRegular
import timber.log.Timber

class DataLoader(private val practiceType: PracticeType) {
    
    private val difficultData by lazy {
        App.daoSession?.findAllDifficult(practiceType)
    }

    val allPracticeData by lazy {
        if (practiceType.type == PracticeType.TYPE_DIFFICULTY){
            difficultData?.map { it.first }
        }else{
            getAllPractice()
        }

    }

    val allRecordData by lazy {
        if (practiceType.type == PracticeType.TYPE_DIFFICULTY){
            difficultData?.map { it.second }
        }else{
            getAllRecord()
        }

    }

    private fun getAllPractice():List<PracticeData>?{

        return App.daoSession?.findAllPractice(practiceType)
    }

    private fun getAllRecord():List<RecordData>?{


        return App.daoSession?.findAllRecord(practiceType)
    }

    fun getExamRegular():List<ExamRegular>? = App.daoSession?.getExamRegulars(practiceType)

    /**
     * 统计 所有地区车型 科目 题库
     */
    fun countPractice():Int{

        return App.daoSession?.countPractice(practiceType)?:0
    }

    /**
     * 统计 已做题目
     *
     */
    fun countComplete():Int{

        return App.daoSession?.countComplete(practiceType)?:0
    }

    /**
     * 获取章节列表
     */
    fun getChapters():List<Chapter>?{

        return App.daoSession?.findAllChapter(practiceType)
    }


}